home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / ansippv2 / read.me < prev    next >
Text File  |  1988-09-20  |  23KB  |  460 lines

  1.  
  2. Thanks for your gratifying response to my article in Computer Language, July
  3. 1988, titled "Using Tomorrow's C Standard Today".  This disk contains the
  4. latest source and executable code for the ANSI-Conforming C Language
  5. Preprocessor presented there.  This is contained in the archive PPV2.ARC.
  6.  
  7.                              Don Kneller's NDMAKE
  8.  
  9. Also included is Don Kneller's NDMAKE utility, which is used to maintain the
  10. preprocessor.  If you didn't have a MAKE utility before, you now have one of
  11. the best.  If you decide to use it, be sure to support Don's efforts by
  12. becoming a legal user of NDMAKE.  This is contained in the archive
  13. NDMAKE43.ARC.
  14.  
  15. I have included NDMAKE at no charge.  Any charge for this disk is for the
  16. preprocessor, not NDMAKE.
  17.  
  18. Don also markets a commercial version with even more features, called OPUS
  19. Make.  It is available from:
  20.  
  21.         OPUS Software
  22.         D.G. Kneller and J.F. Thomason
  23.         1032 Irving Street
  24.         Suite 439
  25.         San Francisco, CA 94122
  26.  
  27.                                Phil Katz's PKPAK
  28.  
  29. Both archives may be unpacked using Phil Katz's unsurpassed PKPAK (formerly
  30. PKARC) utility, which is contained in the self-extracting archive PK361.EXE.
  31. Simply running PK361.EXE will unpack Phil's program and documentation into
  32. the current directory.  Again, if you find PKPAK useful, please register with
  33. Phil as a legal user.
  34.  
  35. (Phil and his company PKWARE have recently been the target of a lawsuit by
  36. SEA, with whose ARC.EXE program PKPAK is compatible.  You may read the text of
  37. their settlement and decide for yourself, but many people think that Phil was
  38. treated unfairly.  By providing us with a fast and useful tool, he exposed
  39. himself to this kind of action, and so we all owe him a great deal.)
  40.  
  41. I have included PKPAK at no charge.  Any charge for this disk is for the
  42. preprocessor, not PKPAK.
  43.  
  44.                             Revision Control System
  45.  
  46. I hope that you will learn from examining this source code.  I also hope that
  47. you will make changes to it, so that it better suits your needs.  If you do,
  48. you will probably find a revision control system as useful as I do.  One of
  49. the most affordable, as well as fast and capable, is TLIB, available from:
  50.  
  51.         Burton Systems Software
  52.         P.O. Box 4156
  53.         Cary, NC 27519-0156
  54.         (919) 469-3068
  55.  
  56. TLIB allows you to keep track of your revisions as you make them, and also to
  57. merge my changes into your own if I send you a new version.  Once you start
  58. using a revision control system, you just can't stop.
  59.  
  60.                                 The ANSI Draft
  61.  
  62. Anyone who seriously wants to use the preprocessor should obtain a copy of the
  63. ANSI draft from the address in PP.MAN.  Unfortunately, its expensive, but
  64. there's no other way to learn the new features and behavior.
  65.  
  66. The comments in this source code often refer to sections in the ANSI draft.
  67. Those comments, and the entire preprocessor, are based on the draft dated
  68. January 11, 1988, which is already outdated.  If you obtain the ANSI draft
  69. today, you will receive a later revision.  The section numbers should be
  70. close.  Whether the behavior is close depends on the changes they have made.
  71.  
  72.                                The Preprocessor
  73.  
  74. The following files are included in PPV2.ARC:
  75.  
  76.         ANSI.DAT        ANSI "Torture test" examples
  77.         ASSERT.H        An ANSI assert() macro
  78.         ERROR.C         Error message function.
  79.         ERROR.H         Error message function.
  80.         MAKE.INI        Use with Don Kneller's NDMAKE
  81.         MAKEFILE        Use with Don Kneller's NDMAKE
  82.         MEMORY.C        Memory allocation functions.
  83.         MEMORY.H        Memory allocation functions.
  84.         PP.C            Standalone preprocessor.
  85.         PP.EXE          Standalone preprocessor.
  86.         PP.H            Definitions for PP.LIB.
  87.         PP.MAN          Brief description of usage
  88.         PPCHAR.C        Handle trigraph translation.
  89.         PPDIRECT.C      Preprocessor directives.
  90.         PPIFS.C         #if and related directives.
  91.         PPMACRO.C       #define #undef Macro replacement
  92.         PPTOK.C         Tokenizer.
  93.         SYMTAB.C        Hashed symbol table functions.
  94.         SYMTAB.H        Hashed symbol table functions.
  95.         VERS2.H         A little file used by ANSI.DAT.
  96.  
  97.                           Differences From Version 1
  98.  
  99. The following are a list of differences between Version 1 and Version 2 of the
  100. preprocessor.  Any user who has made changes to the Version 1 source code may
  101. contact me to receive a full TLIB revision history of my changes.  This would
  102. allow that user to use TLIB to merge my changes with his or her own.
  103.  
  104. The preprocessor now runs about twice as fast, due to compilation with the
  105. Watcom C Compiler.
  106.  
  107. The source code itself is closer to ANSI-Conformance, although it still fails
  108. to conform in many places.  The primary change is to use prototype function
  109. declarations.  Note that the this comment applies to the source code itself,
  110. not to the function of the program.  It has always been intended that the
  111. program functions as an ANSI-Conforming C Language Preprocessor.  It is
  112. possible for non-conforming C source code to fit that function.
  113.  
  114. A bug was corrected that produced an incorrect macro replacement or a
  115. diagnostic when any macro invocation contained a parameter that began with a
  116. left parenthesis.  For example, the input:
  117.  
  118.         #define str(x) / #x /
  119.         #define cat(x, y) | #x #y |
  120.  
  121.         These work OK:
  122.  
  123.         str(test)
  124.         cat(left, right)
  125.  
  126.         These work not OK:
  127.  
  128.         str((test))
  129.         cat((left), (right))
  130.  
  131. produces the following output:
  132.  
  133.         These work OK:
  134.  
  135.         / "test" /
  136.         | "leftright" |
  137.  
  138.         These work not OK:
  139.  
  140.         / "(test" /)
  141.         12: Too few macro arguments.
  142.         , (right))
  143.  
  144. A bug was corrected that produced garbage upon certain invalid #include
  145. directives.
  146.  
  147. #pragma directives are now optionally passed through to the output.  Within
  148. passed-through #pragma directives, macros may be replaced, optionally.  If
  149. #pragma pass-through is disabled (as by default), #pragma directives are
  150. silently ignored and discarded.  This change allows the preprocessor to work
  151. correctly with compilers such as Watcom, to whom #pragma directives are
  152. important.  It also allows the preprocessor to correctly handle input that
  153. contains #pragma directives; previously, only the simplest #pragma directives
  154. were discarded without complaint.
  155.  
  156. The preprocessor now scrupulously frees all dynamically allocated memory.
  157. Previously, memory allocated for the symbol table, and certain other data, was
  158. never freed, because it is used throughout the execution of the preprocessor.
  159. This change is only for my peace of mind.  It may be more significant to
  160. others that write programs that call the preprocessor library: a new function,
  161. PPTerminate(), ensures that all memory allocated by the library is freed.
  162.  
  163. Dynamic memory allocation is now performed via malloc() and free().
  164. Previously, the preprocessor library chose between malloc() and sbrk()
  165. depending on the size of the memory to be allocated.  This was important under
  166. the Lattice compiler, whose malloc() and free() are excruciating.  There is no
  167. apparent advantage under Watcom, and sbrk() caused other problems.
  168.  
  169. The NDEBUG macro in ASSERT.H worked backwards.  That is, defining NDEBUG
  170. enabled the assert() macro, instead of disabling it as it should.
  171.  
  172. The __DATE__ and __TIME__ predefined macros are now replaced with the current
  173. date and time, instead of a canned date and time.
  174.  
  175. Other minor changes to the source code and comments.
  176.  
  177.                                  The Compiler
  178.  
  179. This version may be compiled using the Watcom C Compiler version 6.5.  I have
  180. also compiled it with various versions of Microsoft C, and it works.  More on
  181. the Watcom compiler below.
  182.  
  183. If you don't use the Watcom compiler, you can probably use your favorite
  184. compiler instead without too much trouble, provided your compiler can handle
  185. prototype function declarations.  (This eliminates Lattice.)
  186.  
  187.             WARNING!  OPINIONS FOLLOW!  GRAIN OF SALT RECOMMENDED!
  188.  
  189. I give the Watcom compiler my highest possible recommendation.  I have met
  190. some of Watcom's designers, and I have dealt with their support people, and I
  191. am very impressed.  Support, in particular, is a problem area with both
  192. Lattice and Microsoft, because they are simply too big to be able to afford
  193. enough good people in support.  Novell is just as bad.
  194.  
  195. I don't mean to pick on Lattice, Microsoft, and Novell.  There are small
  196. companies with poor support as well.  But I make my living as a programmer,
  197. and these are three companies that I deal with extensively, so I am speaking
  198. from experience.  Their products are of variable, but generally good quality.
  199. Their support is as good as can be expected.  But my expectations of the level
  200. of support from large companies has declined as a result of dealing with them.
  201.  
  202. I have often wondered why technical support suffers as a software company
  203. grows.  It seems to me that if such a company prices its products (and/or its
  204. support) correctly, it should not matter how many units are sold.  Because, if
  205. the price of 100 units covers the cost of supporting those 100 units,
  206. shouldn't the cost of a 1,000 units cover the cost of supporting 1,000 units?
  207. 10,000?  100,000?
  208.  
  209. A friend who is more business-oriented than I am points out one possible
  210. reason.  If it takes one support person to handle 100 units, there's no
  211. management involved.  Ten support people handling 1,000 units might be not
  212. much more complicated.  But when one hundred support people are handling
  213. 10,000 units, suddenly there looms the spectre of management (gasp!).  Now,
  214. phones must be answered (by a less technical person perhaps? sound familiar?),
  215. calls must be tracked in a computer system, someone must perform scheduling,
  216. and so on.  Otherwise the technical people would never be able to keep track
  217. of what's going on.
  218.  
  219. This may be what has happened to Lattice, Microsoft, and Novell.  (I won't
  220. even mention IBM.)  But I don't think so.  I honestly believe (although this
  221. is just speculation, not a statement of fact) that once these large software
  222. companies became large PROFITABLE companies, the business interests took over.
  223.  
  224. No longer was the priority to produce good programs and support them well.
  225. The priority shifted to those areas that produce revenue for the least
  226. investment.  That portion of the price of the product that once covered
  227. support was redirected to advertising, packaging, and new development.  And so
  228. technical support is chronically understaffed.
  229.  
  230. I have heard speculation that, at Microsoft, as soon as a new hire in
  231. technical support shows an uncommon ability to understand the products, he or
  232. she is moved into development, depriving the existing customers of support by
  233. an extremely able person.
  234.  
  235. And perhaps this is as it should be.  After all, whose interests take priority
  236. in any business?  The customers who have already paid their money?  Or the
  237. investors who deserve a maximal return on their investment?  Common business
  238. sense would, in my experience, favor the investors, while giving lip service
  239. to the needs of customers.  This is called free enterprise, and it's what
  240. makes our country great.
  241.  
  242. I'm not being facetious!  I honestly believe that the business people should
  243. be able to run any business as they see fit.  I won't presume to tell them how
  244. to do their jobs.  However, this means that the concerns of business are
  245. fundamentally at odds with my goals as a programmer.
  246.  
  247. My goals are to write software that has some redeeming value and elegance, and
  248. to support it to the best of my ability.  This is why I have distributed this
  249. program in this manner, and why I plug Phil Katz and Don Kneller, above.  None
  250. of Don, Phil, or I have a toll-free, 24-hour support hotline, but we don't
  251. charge for one either.  Nor do we represent that our technical support is a
  252. big part of the value of our programs.  (Lattice, Microsoft, and Novell all
  253. market their support as part of the value of their products.)
  254.  
  255. What is my favorite software that I use daily?  Without question, those
  256. shareware programs like Don Kneller's and Phil Katz's.  The price/performance
  257. ratio on these programs is unheard of.  And the support turns out to be better
  258. than that of most commercial software vendors.
  259.  
  260. Running a close second on my list of favorite software is the Watcom compiler.
  261. We are fortunate that there is a compiler vendor that is not yet so large that
  262. it can't support its products.  Since Watcom is associated with an educational
  263. institution, perhaps the "suits" won't ruin Watcom as it grows.  If you don't
  264. have a C compiler, or if you can afford another, and you don't require
  265. Microsoft C (for Windows or OS/2, for example), get the Watcom compiler.
  266.  
  267. Third on my list of favorite software is the Mortice Kern Systems ports of
  268. various traditional Unix tools.  I have had their AWK language for some time,
  269. and I recently got their "MKS Toolkit".  I am considering investing in their
  270. RCS (Revision Control System, somewhat like TLIB), and I lust after their
  271. justifiably expensive SQPS (TROFF-based document preparation).  Their prices
  272. are reasonable, and when you call on the telephone, you get somebody who knows
  273. what's what.
  274.  
  275.                               More About Watcom C
  276.  
  277. Watcom C is the first C compiler available for the PC-compatible environment
  278. that even approaches conformance with the draft proposed ANSI standard.
  279. Lattice has told me on the phone that their compiler is, in their words,
  280. "ANSI-Conforming".  This indicates how many people still misunderstand what
  281. ANSI Conformance means.  Lattice doesn't even fully support prototype function
  282. declarations.  Microsoft is more honest.  Their documentation states that they
  283. have added ANSI features "in many areas".  Fair enough.
  284.  
  285. But the Watcom compiler is fully ANSI Conforming.  And believe me, their
  286. designers know what that means.  The new version 6.5 even tracks changes in
  287. the draft proposed standard since their original version 6.0.  Until the
  288. standard is approved, compiler vendors will spend much effort tracking the
  289. changes to the draft.  I am impressed that Watcom is willing to do so.
  290. Lattice and Microsoft seem to be taking a "wait for approval" approach.
  291.  
  292. Don't misunderstand me.  I am using the term "ANSI Conforming" to mean "ANSI
  293. Conforming, but all programs have bugs".  I found one minor area of
  294. non-conformance in version 6.0 of the Watcom C compiler's preprocessor.  I
  295. wouldn't say that it rendered the compiler "non-conforming".  Rather, I would
  296. say that it was a bug in a "conforming" implementation.  I made a bug report,
  297. and Watcom, to their credit, took it as such.  I believe it is corrected in
  298. Watcom version 6.5, but I haven't tested it.
  299.  
  300. (Likewise, some of you will find bugs or areas of non-conformance in my
  301. preprocessor.  Please don't bash me for representing the preprocessor as
  302. ANSI-Conforming when it's not.  Instead, report these to me as bugs, and I
  303. will do my best to fix them.)
  304.  
  305. I find the Watcom compiler easier to use than Microsoft's, but that's a matter
  306. of taste.
  307.  
  308. I believe that Watcom generates better code than Microsoft, but the published
  309. reviews and benchmarks are inconclusive.  It's safe to say that they are
  310. neck-and-neck, and so Watcom wins with me because of its other good points.
  311. (Note that I don't even mention Lattice.  My preprocessor runs about twice as
  312. fast when compiled with Watcom as with Lattice, with no significant changes to
  313. the code.  Gives one pause, don't it?)
  314.  
  315. Watcom includes a full-screen, source-level debugger that is similar to
  316. Microsoft's CodeView.  I haven't yet made a judgement which debugger is
  317. better.  Since my job requires me to use CodeView, I suppose I will find out.
  318.  
  319. Watcom also includes a fast, interactive, integrated (edit/compile/debug)
  320. development environment, similar to Microsoft's Quick-C.  I don't use either
  321. one.
  322.  
  323. Speed of compilation is as unimportant to me as anything I can think of.
  324. Watcom's designers have told me that speed of compilation is one of their top
  325. priorities.  In any case, I find both Watcom and Microsoft sufficiently fast.
  326. I speed up Watcom a lot by turning off all optimization until creating a
  327. production version.  You can judge compilation speed for yourself.
  328.  
  329. Watcom has a very interesting set of #pragmas.  You can use a #pragma to
  330. direct Watcom to pass parameters in particular machine registers on a
  331. function-by-function basis.  This permits mixed-language development without
  332. any interface routines.  You can also use a #pragma to cause a function call
  333. to generate in-line code.  This is how Watcom replaces calls to strcpy() and
  334. other functions with inline code (optionally).  It would even be possible,
  335. with some work, to use #pragmas to allow Watcom-compiled code to call the
  336. Microsoft Windows Toolkit libraries directly.  I predict that Watcom's
  337. #pragmas will be put to some very interesting uses.
  338.  
  339. Watcom includes a Unix-like MAKE facility.  I continue to use Don Kneller's
  340. instead because I'm accustomed to it, and because it's closer to Unix's.
  341. Either one is by far preferable to Microsoft's un-Unix-like, verbose,
  342. inflexible MAKE program.
  343.  
  344. Certainly the inclusion of CodeView- and Quick-C-like features indicate that
  345. Watcom intends their compiler to compete head-to-head with Microsoft C 5.0.
  346. Microsoft lists for $450, and Watcom lists for $295.  Watcom has better
  347. support.  Watcom generates better code (I believe).  Watcom's #pragmas make it
  348. much more flexible than Microsoft.  Watcom's MAKE is better.
  349.  
  350. You decide.  I believe that one should choose Microsoft only when Windows or
  351. OS/2 programming is required.  I await Watcom's OS/2 version with pleasant
  352. anticipation.
  353.  
  354.                        Questions About the Preprocessor
  355.  
  356. Some users have asked the following good questions.
  357.  
  358.                         "How does the -d option work?"
  359.  
  360. The -d option defines the following (empty) macro.  For example:
  361.  
  362.         PP -dMACRONAME file.c
  363.  
  364. This command preprocesses FILE.C as if it were preceded by the line:
  365.  
  366.         #define MACRONAME
  367.  
  368. which defines an (empty) macro called MACRONAME.  An empty macro is one whose
  369. name is replaced during preprocessing, but whose replacement list is empty.
  370. The typical use of a macro defined by -d is to test if it is defined:
  371.  
  372.         #ifdef MACRONAME
  373.  
  374. (Note that for this purpose, the replacement list of MACRONAME is
  375. unimportant.)  This allows the PP command line to change the behavior of a
  376. compilation, without requiring changes to the file.
  377.  
  378. The preprocessor source code uses -d as follows:
  379.  
  380.         pp -dNDEBUG ppmacro.c
  381.  
  382. The macro NDEBUG, if defined, disables the assert() macro.  If NDEBUG is not
  383. defined, assert() is armed to test for internal errors (see ANSI).  In this
  384. way, I can turn assert() on and off without making changes to my source files.
  385.  
  386.       "When I redirect the output, why do errors still go to the screen?"
  387.  
  388. The preprocessor uses the Unix philosophy of how commands should work.
  389. Commands should take their input from "standard input", and produce their
  390. output on "standard output".  Standard input and output are the keyboard and
  391. screen, by default, but either or both may be redirected on the command line
  392. to a file.  Or, standard output may be fed directly into another program, as
  393. if through a "pipe".  DOS supports a similar capability.
  394.  
  395. In this way, several Unix-style commands may be connected, as if to form a
  396. "pipeline".  Each performs its transformation on the input to the pipeline,
  397. and the result of all transformations is available at the output of the
  398. pipeline.
  399.  
  400. For example, in the following command:
  401.  
  402.         PP <file.c >file.pp
  403.  
  404. the preprocessor is the whole pipeline, FILE.C is the input, and the
  405. transformed, preprocessed output is redirected to FILE.PP.  When this is done,
  406. why do errors still appear on the screen?
  407.  
  408. To go back to Unix philosophy, programs further down the pipeline (that is,
  409. those who receive the preprocessed output) are only interested in the
  410. transformed, preprocessed data.  On the other hand, the human user, looking at
  411. the screen, is only interested in errors, not necessarily each and every
  412. transformed line that is going down the pipeline.  Therefore, Unix (and DOS)
  413. provide another type of output, "standard error output", which is not
  414. redirected, even if standard output is redirected.
  415.  
  416. Thus, if a program writes its transformed data to standard output, and its
  417. diagnostic output to standard error, everybody gets to see the part of the
  418. output that they're interested in.  The human user gets to see diagnostics,
  419. because standard error is not redirected.  Programs further down the pipeline
  420. get to see the transformed data, because standard output is piped to them.
  421.  
  422. If the user does not redirect standard output, then both the transformed data
  423. and the diagnostics appear intermingled on the screen, as expected.
  424.  
  425.        "Why not pass invalid macro redefinitions through to the output?"
  426.  
  427. What the preprocessor does with invalid input is somewhat arbitrary.
  428. Typically, it throws all or part of it away.  Preprocessor directives,
  429. including macro definitions, are never passed through to the output, whether
  430. valid or not (with the optional except of #pragma directives).  This is the
  431. whole purpose of the preprocessor, to execute the preprocessor directives, and
  432. pass the resulting raw token stream to the output.  Even the #line directives
  433. which may be optionally included in the output do not necessarily relate to
  434. the #line directives in the input.
  435.  
  436.                        "Why does ANSI.DAT cause errors?"
  437.  
  438. ANSI.DAT contains a number of examples of macro definition and replacement
  439. that appear in the draft proposed standard.  Some of these examples are
  440. intended to DEMONSTRATE invalid stuff.  As such, the preprocessor correctly
  441. diagnoses these errors.
  442.  
  443.                                   Good Luck!
  444.  
  445. If you have more questions, or suggestions, please write to me.  I'll try to
  446. be as responsive as I can.
  447.  
  448. Please pass the preprocessor on to interested friends and colleagues.
  449. Encourage them to send me $15 to receive the next version, as I have
  450. encouraged you to support the folks mentioned above.  We're all in this
  451. together.
  452.  
  453. Don't use the preprocessor, or any part of it, in a commercial product,
  454. without first making arrangements with me.  Please do use it in programs that
  455. you distribute freely, without charge.
  456.  
  457.         Steven Bruce Williams
  458.         P.O. Box 8458
  459.         Bridgeport, CT 06605-0997
  460.